<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>
        <input id="username" type="text" placeholder="请输入用户名" />
    </div>
    <div>
        <input id="password" type="text" placeholder="请输入密码" />
    </div>
    <button id="submit">提交</button>
    <button id="get">获取数据</button>
</body>
<script>
    // 1-创建FormData实例对象
    const fd = new FormData();

    document.querySelector('#submit').onclick = function () {
        // 手机表单数据
        const username = document.querySelector('#username').value;
        const password = document.querySelector('#password').value;

        // 将表单数据追加到FormData实例对象中
        fd.append('username', username);
        fd.append('password', password);
    }

    document.querySelector('#get').onclick = function () {
       const username=fd.get('username');
       const password=fd.get('password');
       console.log(username,password);

    }
</script>

</html>